#include <stdio.h>
#define MAXN 1005
#define max(a, b) ((a) > (b) ? (a) : (b))

int weight[MAXN];
int value[MAXN];
int dp[MAXN][MAXN];

int main() {
    int n, T;
    scanf("%d%d", &n, &T);
    for (int i = 1; i <= n; ++i) {
        scanf("%d%d", &weight[i], &value[i]);
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= T; ++j) {
            if (j < weight[i]) {
                dp[i][j] = dp[i-1][j];
            } else {
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-weight[i]] + value[i]);
            }
        }
    }
    printf("%d\n", dp[n][T]);
    return 0;
}
